
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>ModLauncher · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    
    <link rel="prev" href="3.3.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" >
            
                <a target="_blank" href="https://github.com/xfl03/CoreModTutor">
            
                    
                    源代码仓库（求star）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="./">
            
                <a href="./">
            
                    
                    目录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="0.html">
            
                <a href="0.html">
            
                    
                    0 绪论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    1 简介
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="1.1.html">
            
                <a href="1.1.html">
            
                    
                    CoreMod
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="1.2.html">
            
                <a href="1.2.html">
            
                    
                    Java虚拟机
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="1.3.html">
            
                <a href="1.3.html">
            
                    
                    Minecraft混淆方式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    2 Java虚拟机
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" >
            
                <span>
            
                    
                    ClassLoader类加载器
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" >
            
                <span>
            
                    
                    ByteCode字节码
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" >
            
                <span>
            
                    
                    ASM
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    3 原版 CoreMod
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="3.1.html">
            
                <a href="3.1.html">
            
                    
                    直接修改class文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="3.2.html">
            
                <a href="3.2.html">
            
                    
                    JavaAgent
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="3.3.html">
            
                <a href="3.3.html">
            
                    
                    LaunchWrapper
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.6.4" data-path="3.4.html">
            
                <a href="3.4.html">
            
                    
                    ModLauncher
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <span>
            
                    
                    4 FML CoreMod
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="4.1.html">
            
                <a href="4.1.html">
            
                    
                    1.3.2-1.5.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="4.2.html">
            
                <a href="4.2.html">
            
                    
                    1.6.1-1.12.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="4.3.html">
            
                <a href="4.3.html">
            
                    
                    1.13.2-1.14.4
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="5.html">
            
                <a href="5.html">
            
                    
                    5 Mixin
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="5.1.html">
            
                <a href="5.1.html">
            
                    
                    配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="5.2.html">
            
                <a href="5.2.html">
            
                    
                    引导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="5.3.html">
            
                <a href="5.3.html">
            
                    
                    注入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="5.4.html">
            
                <a href="5.4.html">
            
                    
                    修改
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="5.5.html">
            
                <a href="5.5.html">
            
                    
                    定位
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="5.6.html">
            
                <a href="5.6.html">
            
                    
                    融合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="5.7.html">
            
                <a href="5.7.html">
            
                    
                    扩展
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="5.8.html">
            
                <a href="5.8.html">
            
                    
                    调试
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" >
            
                <span>
            
                    
                    附录
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="附录A.html">
            
                <a href="附录A.html">
            
                    
                    附录A 相关工具下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="附录B.html">
            
                <a href="附录B.html">
            
                    
                    附录B 常见Java字节码指令表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="附录C.html">
            
                <a href="附录C.html">
            
                    
                    附录C 参考资料
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >ModLauncher</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="modlauncher">ModLauncher</h1>
<ul>
<li>cpw&#x5236;&#x4F5C;&#xFF0C;&#x7528;&#x4E8E;1.13FML&#x52A0;&#x8F7D;&#x7684;&#x5E93;&#xFF0C;&#x5438;&#x53D6;&#x4E86;LaunchWrapper&#x7684;&#x7ECF;&#x9A8C;&#xFF0C;&#x5E76;&#x4F7F;&#x7528;&#x4E86;StreamAPI&#x548C;ServiceLoader&#x7B80;&#x5316;&#x4EE3;&#x7801;&#x3002;</li>
<li>&#x4F1A;&#x8BB0;&#x5F55;&#x6BCF;&#x4E00;&#x4E2A;&#x7C7B;&#x88AB;<code>ITransformationService</code>&#x548C;<code>ILaunchPluginService</code>&#x8BF7;&#x6C42;&#x4FEE;&#x6539;&#x7684;&#x5386;&#x53F2;&#x3002;</li>
</ul>
<h2 id="&#x52A0;&#x8F7D;&#x6D41;&#x7A0B;">&#x52A0;&#x8F7D;&#x6D41;&#x7A0B;</h2>
<p><a href="https://github.com/cpw/modlauncher/blob/master/src/main/java/cpw/mods/modlauncher/Launcher.java" target="_blank">Launcher</a>&#x7C7B;&#x662F;ModLauncher&#x7684;&#x5165;&#x53E3;&#x7C7B;&#xFF1A;</p>
<ul>
<li><p>&#x5728;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x4E2D;&#xFF0C;&#x521D;&#x59CB;&#x5316;&#x4E86;&#x7528;&#x4E8E;&#x5B58;&#x50A8;Transformer&#x7684;<code>TransformStore</code>&#xFF0C;&#x4EE5;&#x53CA;&#x7528;&#x4E8E;&#x521D;&#x59CB;&#x5316;<code>ITransformationService</code>&#x7684;<code>TransformationServicesHandler</code></p>
<pre><code class="lang-java"><span class="hljs-keyword">this</span>.transformStore = <span class="hljs-keyword">new</span> TransformStore();
<span class="hljs-keyword">this</span>.transformationServicesHandler = <span class="hljs-keyword">new</span> TransformationServicesHandler(<span class="hljs-keyword">this</span>.transformStore);
</code></pre>
</li>
<li><p>&#x5728;<code>run</code>&#x65B9;&#x6CD5;&#x4E2D;&#xFF0C;&#x8C03;&#x7528;<code>TransformationServicesHandler</code>&#x7684;&#x521D;&#x59CB;&#x5316;&#x65B9;&#x6CD5;&#xFF0C;&#x5E76;&#x521B;&#x5EFA;<code>TransformingClassLoader</code>&#xFF0C;&#x6700;&#x540E;&#x542F;&#x52A8;&#x6E38;&#x620F;</p>
<pre><code class="lang-java"><span class="hljs-keyword">this</span>.transformationServicesHandler.initializeTransformationServices(<span class="hljs-keyword">this</span>.argumentHandler, <span class="hljs-keyword">this</span>.environment);
...
<span class="hljs-keyword">this</span>.classLoader = <span class="hljs-keyword">this</span>.transformationServicesHandler.buildTransformingClassLoader(<span class="hljs-keyword">this</span>.launchPlugins, classLoaderBuilder);
Thread.currentThread().setContextClassLoader(<span class="hljs-keyword">this</span>.classLoader);
<span class="hljs-keyword">this</span>.launchService.launch(<span class="hljs-keyword">this</span>.argumentHandler, <span class="hljs-keyword">this</span>.classLoader);
</code></pre>
</li>
</ul>
<p>&#x5728;<code>TransformationServicesHandler</code>&#x4E2D;&#xFF0C;&#x521D;&#x59CB;&#x5316;&#x4E86;<code>ITransformationService</code>&#xFF1A;</p>
<ul>
<li><p>&#x5728;&#x6784;&#x9020;&#x5668;&#x4E2D;&#xFF0C;&#x4F7F;&#x7528;&#x4E86;ServiceLoader&#x6765;&#x83B7;&#x5F97;<code>ITransformationService</code>&#x5B9E;&#x4F8B;&#xFF0C;&#x5E76;&#x521B;&#x5EFA;&#x5BF9;&#x5E94;&#x7684;<code>TransformationServiceDecorator</code>&#x7528;&#x6765;&#x521D;&#x59CB;&#x5316;&#x524D;&#x8005;</p>
<pre><code class="lang-java">transformationServices = ServiceLoaderStreamUtils.errorHandlingServiceLoader(ITransformationService.class, serviceConfigurationError -&gt; LOGGER.fatal(MODLAUNCHER, <span class="hljs-string">&quot;Encountered serious error loading transformation service, expect problems&quot;</span>, serviceConfigurationError));
serviceLookup = ServiceLoaderStreamUtils.toMap(transformationServices, ITransformationService::name, TransformationServiceDecorator::<span class="hljs-keyword">new</span>);
</code></pre>
</li>
<li><p>&#x5728;<code>initializeTransformationServices</code>&#x65B9;&#x6CD5;&#x4E2D;&#x5206;&#x522B;&#x901A;&#x8FC7;<code>TransformationServiceDecorator</code>&#x95F4;&#x63A5;&#x8C03;&#x7528;<code>ITransformationService</code>&#x5BF9;&#x5E94;&#x7684;&#x65B9;&#x6CD5;</p>
<pre><code class="lang-java">loadTransformationServices(environment);
...
initialiseTransformationServices(environment);
initialiseServiceTransformers();
</code></pre>
</li>
</ul>
<p>&#x5728;<code>TransformationServiceDecorator</code>&#x4E2D;&#xFF1A;</p>
<ul>
<li><code>gatherTransformers</code>&#x65B9;&#x6CD5;&#x4ECE;<code>ITransformationService</code>&#x7684;<code>transformers</code>&#x65B9;&#x6CD5;&#x4E2D;&#x83B7;&#x5F97;&#x4E86;<code>ITransformer</code>&#x7684;&#x5B9E;&#x4F8B;&#xFF0C;&#x5E76;&#x5728;<code>TransformStore</code>&#x4E2D;&#x6839;&#x636E;<code>targets</code>&#x65B9;&#x6CD5;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x6CE8;&#x518C;&#x4E86;<code>Target</code>&#x5BF9;&#x5E94;&#x7684;<code>ITransformer</code><pre><code class="lang-java"><span class="hljs-keyword">final</span> List&lt;ITransformer&gt; transformers = <span class="hljs-keyword">this</span>.service.transformers();
...
<span class="hljs-keyword">for</span> (Type type : transformersByType.keySet()) {
  ...
  <span class="hljs-keyword">for</span> (ITransformer&lt;?&gt; xform : transformersByType.get(type)) {
      <span class="hljs-keyword">final</span> Set&lt;ITransformer.Target&gt; targets = xform.targets();
      ...
      <span class="hljs-keyword">final</span> Map&lt;TransformTargetLabel.LabelType, List&lt;TransformTargetLabel&gt;&gt; labelTypeListMap = targets.stream().map(TransformTargetLabel::<span class="hljs-keyword">new</span>).collect(Collectors.groupingBy(TransformTargetLabel::getLabelType));
      ...
      labelTypeListMap.values().stream().flatMap(Collection::stream).forEach(target -&gt; transformStore.addTransformer(target, xform));
  }
}
</code></pre>
</li>
</ul>
<p><code>ITransformer</code>&#x7684;&#x52A0;&#x8F7D;&#x6D41;&#x7A0B;&#x81F3;&#x6B64;&#x544A;&#x4E00;&#x6BB5;&#x843D;&#xFF0C;&#x73B0;&#x5728;&#x770B;&#x5230;<code>TransformingClassLoader</code>&#x5728;&#x7C7B;&#x52A0;&#x8F7D;&#x65F6;&#x7684;&#x884C;&#x4E3A;&#xFF1A;</p>
<ul>
<li><p><code>TransformingClassLoader</code>&#x662F;&#x4E00;&#x4E2A;<code>ClassLoader</code>&#x7684;&#x5B50;&#x7C7B;&#xFF0C;&#x5176;&#x5185;&#x90E8;&#x7C7B;<code>DelegatedClassLoader</code>&#x662F;<code>URLClassLoader</code>&#x7684;&#x5B50;&#x7C7B;&#xFF0C;&#x5927;&#x90E8;&#x5206;&#x65B9;&#x6CD5;&#x90FD;&#x4F1A;&#x8C03;&#x7528;&#x540E;&#x8005;&#x7684;&#x65B9;&#x6CD5;</p>
</li>
<li><p><code>loadClass</code>&#x65B9;&#x6CD5;&#x4F1A;&#x901A;&#x8FC7;&#x591A;&#x6B21;&#x8C03;&#x7528;&#x6700;&#x7EC8;&#x8C03;&#x7528;<code>DelegatedClassLoader</code>&#x7684;<code>findClass</code>&#x65B9;&#x6CD5;&#xFF0C;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x9996;&#x5148;&#x8BFB;&#x5165;&#x4E8C;&#x8FDB;&#x5236;&#x7684;&#x7C7B;&#x6587;&#x4EF6;&#xFF0C;&#x7136;&#x540E;&#x8C03;&#x7528;<code>ClassTransformer</code>&#x7684;<code>transform</code>&#x65B9;&#x6CD5;&#xFF0C;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x4F1A;&#x8C03;&#x7528;<code>ITransformer</code>&#x7684;<code>transform</code></p>
</li>
</ul>
<pre><code class="lang-java"><span class="hljs-keyword">final</span> String path = name.replace(<span class="hljs-string">&apos;.&apos;</span>, <span class="hljs-string">&apos;/&apos;</span>).concat(<span class="hljs-string">&quot;.class&quot;</span>);

<span class="hljs-keyword">final</span> URL classResource = classBytesFinder.apply(path);
<span class="hljs-keyword">byte</span>[] classBytes;
<span class="hljs-comment">//&#x7701;&#x7565;&#x8BFB;&#x5165;&#x6587;&#x4EF6;&#x7684;&#x4EE3;&#x7801;</span>
classBytes = tcl.classTransformer.transform(classBytes, name);
</code></pre>
<h2 id="&#x5236;&#x4F5C;&#x65B9;&#x6CD5;">&#x5236;&#x4F5C;&#x65B9;&#x6CD5;</h2>
<p>&#x901A;&#x8FC7;&#x4EE5;&#x4E0A;&#x7B80;&#x5355;&#x7684;&#x6D41;&#x7A0B;&#x5206;&#x6790;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x83B7;&#x5F97;&#x4E09;&#x4E2A;&#x76F8;&#x5173;&#x7684;&#x4FE1;&#x606F;&#x2014;&#x2014;<code>ITransformationService</code>&#x3001;<code>ITransformer</code>&#x4E0E;ServiceLoader&#x3002;</p>
<h3 id="itransformationservice">ITransformationService</h3>
<p>ITransformationService&#x662F;&#x4E00;&#x4E2A;&#x7528;&#x6765;&#x9884;&#x5904;&#x7406;&#x73AF;&#x5883;&#x5E76;&#x63D0;&#x4F9B;<code>ITransformer</code>&#x5B9E;&#x4F8B;&#x7684;&#x63A5;&#x53E3;&#xFF0C;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x4EE5;&#x4E0B;&#x65B9;&#x6CD5;&#xFF1A;</p>
<ul>
<li><code>name</code>&#xFF0C;&#x8FD4;&#x56DE;Service&#x7684;&#x540D;&#x79F0;</li>
<li><code>arguments</code>&#xFF0C;&#x4F20;&#x5165;&#x4E00;&#x4E2A;&#x53CC;&#x53C2;&#x6570;<code>Function</code>&#x6765;&#x6307;&#x5B9A;&#x9700;&#x8981;&#x8BFB;&#x53D6;&#x7684;&#x6E38;&#x620F;&#x53C2;&#x6570;&#xFF0C;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x4EE3;&#x8868;&#x7740;&#x8981;&#x8BFB;&#x53D6;&#x7684;&#x53C2;&#x6570;&#x540D;&#xFF0C;&#x6700;&#x7EC8;&#x8BFB;&#x53D6;&#x7684;&#x53C2;&#x6570;&#x4F1A;&#x53D8;&#x4E3A;&quot;Service&#x540D;.&#x53C2;&#x6570;&#x540D;&quot;&#x7684;&#x5F62;&#x5F0F;&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x4EE3;&#x8868;&#x7740;&#x53C2;&#x6570;&#x7684;&#x63CF;&#x8FF0;</li>
<li><code>argumentValues</code>&#xFF0C;&#x4F20;&#x5165;&#x8BFB;&#x53D6;&#x53C2;&#x6570;&#x7684;&#x7ED3;&#x679C;</li>
<li><code>initialize</code>&#xFF0C;&#x521D;&#x59CB;&#x5316;&#x65B9;&#x6CD5;&#xFF0C;&#x4F20;&#x5165;&#x73AF;&#x5883;&#xFF0C;&#x5207;&#x8BB0;&#x4E0D;&#x8981;&#x8C03;&#x7528;Minecraft&#x3001;&#x5176;&#x4ED6;Mod&#x3001;&#x81EA;&#x5DF1;Mod&#x7684;&#x666E;&#x901A;&#x90E8;&#x5206;&#x7684;&#x4EFB;&#x4F55;&#x4EE3;&#x7801;&#xFF0C;&#x4E0D;&#x7136;&#x4F1A;&#x5BFC;&#x81F4;&#x7C7B;&#x88AB;&#x63D0;&#x524D;&#x52A0;&#x8F7D;&#x800C;&#x51FA;&#x9519;</li>
<li><code>onLoad</code>&#xFF0C;&#x52A0;&#x8F7D;Service&#x65F6;&#x8C03;&#x7528;&#xFF0C;&#x4F20;&#x5165;&#x73AF;&#x5883;&#x53CA;&#x5176;&#x4ED6;Service&#x7684;&#x5217;&#x8868;</li>
<li><code>transformers</code>&#xFF0C;&#x8FD4;&#x56DE;<code>ITransformer</code>&#x7684;&#x5B9E;&#x4F8B;</li>
</ul>
<p>&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x5B9E;&#x4F8B;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.example;

<span class="hljs-keyword">import</span> cpw.mods.modlauncher.api.IEnvironment;
<span class="hljs-keyword">import</span> cpw.mods.modlauncher.api.ITransformationService;
<span class="hljs-keyword">import</span> cpw.mods.modlauncher.api.ITransformer;

<span class="hljs-keyword">import</span> joptsimple.OptionResult;
<span class="hljs-keyword">import</span> joptsimple.OptionSpecBuilder;

<span class="hljs-keyword">import</span> java.util.Arrays;
<span class="hljs-keyword">import</span> java.util.Set;
<span class="hljs-keyword">import</span> java.util.function.BiFunction;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ExampleService</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">ITransformationService</span> </span>{
    <span class="hljs-function">String <span class="hljs-title">name</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;ExampleService&quot;</span>;
    }
    <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">initialize</span><span class="hljs-params">(IEnvironment environment)</span> </span>{}
    <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">onLoad</span><span class="hljs-params">(IEnvironment env, Set&lt;String&gt; otherServices)</span> <span class="hljs-keyword">throws</span> IncompatibleEnvironmentException </span>{}
    <span class="hljs-function">List&lt;ITransformer&gt; <span class="hljs-title">transformers</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> Arrays.asList(<span class="hljs-keyword">new</span> ExampleTransformer());
    }
}
</code></pre>
<h3 id="itransformer">ITransformer</h3>
<p>&#x8FD9;&#x4E2A;<code>ITransformer</code>&#x4E0E;LaunchWrapper&#x7684;<code>IClassTransformer</code>&#x76F8;&#x6BD4;&#x6709;&#x4E24;&#x5927;&#x4E0D;&#x540C;&#xFF1A;</p>
<ul>
<li>&#x4E0D;&#x518D;&#x63A5;&#x6536;&#x4E8C;&#x8FDB;&#x5236;class&#x6587;&#x4EF6;&#xFF0C;&#x8F6C;&#x4E3A;asm&#x7684;node</li>
<li>&#x63D0;&#x65E9;&#x58F0;&#x660E;&#x5C06;&#x8981;&#x4FEE;&#x6539;&#x7684;&#x7C7B;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x7B49;&#x5230;<code>transform</code>&#x65B9;&#x6CD5;&#x4E2D;&#x518D;&#x786E;&#x5B9A;</li>
</ul>
<p><code>ITransformer</code>&#x4F5C;&#x4E3A;&#x4FEE;&#x6539;&#x7C7B;&#x7684;&#x63A5;&#x53E3;&#xFF0C;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x4EE5;&#x4E0B;&#x65B9;&#x6CD5;&#xFF1A;</p>
<ul>
<li><code>transform</code>&#x65B9;&#x6CD5;&#x63A5;&#x6536;asm&#x7684;node&#x548C;node&#x76F8;&#x5173;&#x7684;&#x4FE1;&#x606F;&#xFF0C;&#x8FD9;&#x4E2A;node&#x7684;&#x7C7B;&#x578B;&#x7531;&#x6CDB;&#x578B;T&#x6765;&#x786E;&#x5B9A;&#xFF0C;&#x4E00;&#x822C;&#x4E3A;ClassNode&#x6216;MethodNode</li>
<li><code>castVote</code>&#xFF0C;&#x8FD4;&#x56DE;<code>TransformerVoteResult</code>&#x6765;&#x51B3;&#x5B9A;&#x662F;&#x5426;&#x4FEE;&#x6539;&#x4E00;&#x4E2A;&#x7C7B;&#x6216;&#x65B9;&#x6CD5;<ul>
<li><code>YES</code>&#x4F1A;&#x8C03;&#x7528;<code>transform</code>&#x65B9;&#x6CD5;</li>
<li><code>NO</code>&#x4F1A;&#x8DF3;&#x8FC7;&#x8FD9;&#x4E2A;&#x7C7B;&#x4FEE;&#x6539;&#x5668;</li>
<li><code>REJECT</code>&#x4F1A;&#x629B;&#x51FA;<code>VoteRejectedException</code>&#x9519;&#x8BEF;</li>
<li><code>DEFER</code>&#x4F1A;&#x629B;&#x51FA;<code>VoteDeadlockException</code>&#x9519;&#x8BEF;</li>
</ul>
</li>
<li><code>targets</code>&#xFF0C;&#x8FD4;&#x56DE;&#x9700;&#x8981;&#x4FEE;&#x6539;&#x7684;&#x76EE;&#x6807;<code>Target</code>&#x5217;&#x8868;&#xFF0C;&#x9700;&#x8981;&#x7EDF;&#x4E00;Target&#x7684;&#x7C7B;&#x578B;&#xFF0C;&#x53EA;&#x6709;&#x5728;&#x8FD9;&#x91CC;&#x8FD4;&#x56DE;&#x7684;&#x76EE;&#x6807;&#x624D;&#x4F1A;&#x8C03;&#x7528;&#x53E6;&#x5916;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;</li>
</ul>
<p>&#x4E00;&#x4E2A;&#x6CA1;&#x6709;&#x4FEE;&#x6539;&#x4EFB;&#x4F55;&#x7C7B;&#x7684;&#x5B9E;&#x4F8B;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> com.example;

<span class="hljs-keyword">import</span> cpw.mods.modlauncher.api.ITransformer;
<span class="hljs-keyword">import</span> cpw.mods.modlauncher.api.ITransformerVotingContext;
<span class="hljs-keyword">import</span> cpw.mods.modlauncher.api.TransformerVoteResult;

<span class="hljs-keyword">import</span> org.objectweb.asm.tree.ClassNode;

<span class="hljs-keyword">import</span> java.util.HashSet;
<span class="hljs-keyword">import</span> java.util.Set;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ExampleTransformer</span> <span class="hljs-keyword">implements</span>  <span class="hljs-title">ITransformer</span>&lt;<span class="hljs-title">ClassNode</span>&gt; </span>{
    <span class="hljs-function">ClassNode <span class="hljs-title">transform</span><span class="hljs-params">(ClassNode input, ITransformerVotingContext context)</span> </span>{
        <span class="hljs-keyword">return</span> input;
    }
    <span class="hljs-function">TransformerVoteResult <span class="hljs-title">castVote</span><span class="hljs-params">(ITransformerVotingContext context)</span> </span>{
        <span class="hljs-keyword">return</span> TransformerVoteResult.YES;
    }
    <span class="hljs-function">Set&lt;Target&gt; <span class="hljs-title">targets</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> HashSet&lt;Target&gt;(Arrays.asList(Target.targetClass(<span class="hljs-string">&quot;abc&quot;</span>)));
    }
}
</code></pre>
<h3 id="serviceloader">ServiceLoader</h3>
<p>&#x5B8C;&#x6210;&#x7F16;&#x5199;&#x4E86;<code>ITransformationService</code>&#x4EE5;&#x53CA;<code>ITransformer</code>&#x4EE5;&#x540E;&#xFF0C;&#x6211;&#x4EEC;&#x8FD8;&#x9700;&#x8981;&#x58F0;&#x660E;<code>ITransformationService</code>&#x5B9E;&#x73B0;&#xFF0C;&#x4EE5;&#x4FBF;ModLauncher&#x4F7F;&#x7528;ServiceLoader&#x8FDB;&#x884C;&#x52A0;&#x8F7D;&#x3002;<br>&#x521B;&#x5EFA;<code>META-INF/services/cpw.mods.modlauncher.api.ITransformationService</code>&#xFF0C;&#x5C06;<code>ITransformationService</code>&#x5B9E;&#x73B0;&#x7684;&#x5B8C;&#x6574;&#x7C7B;&#x540D;&#x5199;&#x5165;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;</p>
<pre><code>com.example.ExampleService
</code></pre><h2 id="&#x5B89;&#x88C5;&#x65B9;&#x6CD5;">&#x5B89;&#x88C5;&#x65B9;&#x6CD5;</h2>
<h3 id="&#x5E93;&#x6587;&#x4EF6;&#x6302;&#x8F7D;">&#x5E93;&#x6587;&#x4EF6;&#x6302;&#x8F7D;</h3>
<ul>
<li>&#x590D;&#x5236;&#x7248;&#x672C;json&#x5230;&#x53E6;&#x4E00;&#x4E2A;&#x7248;&#x672C;&#x6587;&#x4EF6;&#x5939;&#x4E2D;&#xFF0C;&#x5E76;&#x4FEE;&#x6539;&#x5BF9;&#x5E94;&#x7684;&#x540D;&#x79F0;</li>
<li>&#x5728;<code>libraries</code>&#x4E2D;&#x52A0;&#x5165;ModLauncher&#x53CA;&#x5176;&#x4F9D;&#x8D56;&#x4EE5;&#x53CA;&#x81EA;&#x5DF1;&#x7F16;&#x5199;&#x7684;CoreMod</li>
<li>&#x4FEE;&#x6539;<code>mainClass</code>&#x4E3A;<code>cpw.mods.modlauncher.Launcher</code></li>
</ul>
<h3 id="&#x4F7F;&#x7528;forge&#x52A0;&#x8F7D;">&#x4F7F;&#x7528;Forge&#x52A0;&#x8F7D;</h3>
<p>&#x4ECE;Forge 1.13.2-25.0.216&#x5F00;&#x59CB;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;Forge&#x6765;&#x52A0;&#x8F7D;&#x65E0;&#x8BBA;&#x662F;&#x5426;&#x5305;&#x542B;&#x666E;&#x901A;Mod&#x7684;ModLauncher CoreMod&#x3002;  </p>
<ul>
<li>&#x653E;&#x5165;<code>.minecraft/mods</code>&#x6587;&#x4EF6;&#x5939;&#x5373;&#x53EF;</li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="3.3.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: LaunchWrapper">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"ModLauncher","level":"1.6.4","depth":2,"next":{"title":"4 FML CoreMod","level":"1.7","depth":1,"ref":"","articles":[{"title":"1.3.2-1.5.2","level":"1.7.1","depth":2,"path":"4.1.md","ref":"4.1.md","articles":[]},{"title":"1.6.1-1.12.2","level":"1.7.2","depth":2,"path":"4.2.md","ref":"4.2.md","articles":[]},{"title":"1.13.2-1.14.4","level":"1.7.3","depth":2,"path":"4.3.md","ref":"4.3.md","articles":[]}]},"previous":{"title":"LaunchWrapper","level":"1.6.3","depth":2,"path":"3.3.md","ref":"3.3.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"3.4.md","mtime":"2019-09-08T03:23:39.423Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-09-08T04:47:05.818Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

